# -*- coding: utf-8 -*-

import operator

#7 = 111b 5=101b

def f(x,y):
    if x==0 or x==1:
        if y%4==0:
            return y
        if y%4==1:
            return 1
        if y%4==2:
            return y+1
        if y%4==3:
            return 0
    else:
        return operator.xor(f(0,x-1),f(0,y))

size,query_no=map(int,raw_input().split())
array=map(int,raw_input().split())


for i in range(query_no):
    lj,rj=map(int,raw_input().split())
    maxv=0
    for x in range(lj,rj+1):
        for y in range(lj,rj+1):
            ax= array[x-1]
            ay= array[y-1]
            if ax<=ay:
                maxv=max(maxv,f(ax,ay))
    print maxv
            